package com.ruoyi.fep.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.fep.domain.Orders;
import com.ruoyi.fep.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fep.mapper.InstallmentsMapper;
import com.ruoyi.fep.domain.Installments;
import com.ruoyi.fep.service.IInstallmentsService;

/**
 * 付款详情Service业务层处理
 * 
 * @author zj
 * @date 2023-04-12
 */
@Service
public class InstallmentsServiceImpl implements IInstallmentsService 
{
    @Autowired
    private InstallmentsMapper installmentsMapper;
    @Autowired
    private OrdersMapper ordersMapper;

    /**
     * 查询付款详情
     * 
     * @param payId 付款详情主键
     * @return 付款详情
     */
    @Override
    public Installments selectInstallmentsByPayId(Long payId)
    {
        return installmentsMapper.selectInstallmentsByPayId(payId);
    }

    /**
     * 查询付款详情列表
     * 
     * @param installments 付款详情
     * @return 付款详情
     */
    @Override
    public List<Installments> selectInstallmentsList(Installments installments)
    {
        List<Installments> installmentsList = installmentsMapper.selectInstallmentsList(installments);
        for (int i = 0; i < installmentsList.size(); i++) {
            Installments installment = installmentsList.get(i);
            String orderNo = installment.getOrderNo();
            System.out.println("1111--------"+orderNo);
            Orders orders = ordersMapper.selectOrdersByOrderNo(orderNo);
            System.out.println("order------->"+orders);
            installment.setOrders(orders);

        }
        return installmentsList;
    }

    /**
     * 新增付款详情
     * 
     * @param installments 付款详情
     * @return 结果
     */
    @Override
    public int insertInstallments(Installments installments)
    {
        installments.setCreateTime(DateUtils.getNowDate());
        return installmentsMapper.insertInstallments(installments);
    }

    /**
     * 修改付款详情
     * 
     * @param installments 付款详情
     * @return 结果
     */
    @Override
    public int updateInstallments(Installments installments)
    {
        installments.setUpdateTime(DateUtils.getNowDate());
        return installmentsMapper.updateInstallments(installments);
    }

    /**
     * 批量删除付款详情
     * 
     * @param payIds 需要删除的付款详情主键
     * @return 结果
     */
    @Override
    public int deleteInstallmentsByPayIds(Long[] payIds)
    {
        return installmentsMapper.deleteInstallmentsByPayIds(payIds);
    }

    /**
     * 删除付款详情信息
     * 
     * @param payId 付款详情主键
     * @return 结果
     */
    @Override
    public int deleteInstallmentsByPayId(Long payId)
    {
        return installmentsMapper.deleteInstallmentsByPayId(payId);
    }
}
